"use strict";
var loading = !1
  , app = new Vue({
    el: "#app",
    data: {
        data: [],
        userId: "",
        ajaxUrl: "",
        cityId: "",
        type: 0,
        pageIndex: 1,
        pageSize: 10,
        keywords: "",
        hideing: !0,
        searchType:0,//首页搜索结果类型：1资讯、2展会、3印厂、4设备、5招聘企业、6招聘职位
                    //分站搜索结果类型：1求购、2供应、3企业库、4招聘企业、5招聘职位、6人物、7访谈、8动态、9心情、10二手
    },
    created: function() {
        FastClick.attach(document.body),
        $(document.body).infinite(),
        this.cityId = $.getPara("cityId"),//分站城市id
        this.cityId ? this.ajaxUrl = " /api/search/search/substation/v2" : this.ajaxUrl = " /api/search/search/index/v2",
        this.keywords = $.getPara("keywords"),//关键词
        this.userId = parseInt($.getStorage("userId")),
        this.getData();
    },
    mounted: function() {
        var e = this;
        this.$nextTick(function() {
            $(document.body).infinite().on("infinite", function() {
                loading || (loading = !0,
                e.hideing = !1,
                setTimeout(function() {
                    var t = e.pageIndex;
                    t++,
                    e.pageIndex = t,
                    e.getData(),
                    loading = !1
                }, 1500))
            })
        })
    },
    methods: {
        getData: function() {
            var i = this;
            $.ajax({
                url: i.ajaxUrl,
                type: "POST",
                dataType: "json",
                data: {
                    userId: i.userId,
                    keywords: i.keywords,
                    cityId: i.cityId,
                    pageIndex: i.pageIndex,
                    pageSize: i.pageSize
                },
                success: function(t) {
                    console.log(t);
                    if (200 == t.code)
                        if (0 < i.data.length) {
                            var e = t.data.list;
                            if (0 < e.length) {
                                var a = i.data.concat(e);
                                i.data = a
                            } else
                                $.toast("没有更多了...", "text"),
                                loading = !0;
                            i.hideing = !0
                        } else
                            i.data = t.data.list;
                    else
                        $.toast("加载失败，请重试！", "text")
                },
                error: function() {
                    $.toast("获取数据失败，请重试！", "text")
                }
            })
        },
        urlHref: function(t) {
            console.log(t,"当前对象",this.cityId);
            let _type = t.object_type;//对象类型 
            let _id = t.id;//对象id
            var para = {};
             para.type = "searchResult";
            //先判断是否分站
            if(this.cityId && this.cityId>0){

                console.log("分站");
                if(_type == "求购" ){
                    para.title = "求购详情";
                    para.url = '/template/buyDetails.html?id='+_id+"&cityId="+this.cityId;
                }else if(_type == "供应"){
                    para.title = "供应详情";
                    para.url = '/template/buyDetails.html?id='+_id+"&cityId="+this.cityId;
                }else if(_type == "企业库"){
                    para.title = "企业库详情";
                    para.url = '/PageClassify/html/Substation/enterpriseDetails.html?id='+_id+"&cityId="+this.cityId;
                }else if(_type == "动态"){
                    para.title = "动态详情";
                    para.url = '/PageClassify/html/Substation/Character/subCharacterDetails.html?id='+_id+"&cityId="+this.cityId;
                }else if(_type == "心情"){
                    para.title = "心情详情";
                    para.url = '/PageClassify/html/Substation/Dynamic/mooddetail.html?id='+_id+"&cityId="+this.cityId;
                }else if(_type == "二手"){
                    para.title = "二手详情";
                    para.url = '/PageClassify/html/Substation/secondhand/secondhandDetails.html?id='+_id+"&cityId="+this.cityId;
                }else if(_type == "招聘企业"){
                    para.title = "招聘企业详情";
                    para.url = '/template/recruitNextDetails.html?id='+_id+"&cityId="+this.cityId;
                }else if(_type == "招聘职位"){
                    para.title = "招聘职位详情";
                    para.url = '/template/recruitDetails.html?id='+_id+"&cityId="+this.cityId;
                }

            }else{
                console.log("主站");
                var cityId = t.city_id;//返回的分站id
                // debugger;
                if(_type == "动态"){
                    para.title = "动态详情";
                    para.url = '/PageClassify/html/Substation/Character/subCharacterDetails.html?id='+_id+"&cityId="+cityId;
                }else
                if(_type == "展会"){
                    para.title = "展会详情";
                    para.url = '/PageClassify/html/Exhibition/exhibitionDetails.html?id='+_id+"&cityId="+cityId;
                }else if(_type == "印厂"){
                    para.title = "印厂详情";
                    para.url = '/template/facDetails.html?id='+_id+"&cityId="+cityId;
                }else if(_type == "设备"){
                    para.title = "设备详情";
                    para.url = '/template/equipmentDetails.html?id='+_id+"&cityId="+cityId;
                }else if(_type == "媒体"){
                    para.title = "媒体详情";
                    para.url = '/template/mediaDetails.html?id='+_id+"&cityId="+cityId;
                }else if(_type == "学院"){
                    para.title = "学院详情";
                    para.url = '/template/collegeDetails.html?id='+_id+"&cityId="+cityId;
                }
                else if(_type == "协会"){
                    para.title = "协会详情";
                    para.url = '/template/assoDetails.html?id='+_id+"&cityId="+cityId;
                }else if(_type == "招聘企业"){
                    para.title = "招聘企业详情";
                    para.url = '/template/recruitNextDetails.html?id='+_id+"&cityId="+cityId;
                }else if(_type == "招聘职位"){
                    para.title = "招聘职位详情";
                    para.url = '/template/recruitDetails.html?id='+_id+"&cityId="+cityId;
                }
            }
            //不同设备
            if (/(Android)/i.test(navigator.userAgent)) { //判断Android
                //是android系统
                // alert("Android系统");
                // jsAndroid.appPush(para)
                jsAndroid.appPush(JSON.stringify(para))
            } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { //判断iPhone|iPad|iPod|iOS
                //默认为iOS系统
                window.webkit.messageHandlers.appPush.postMessage(para);
            } else {
                //pc
                window.location.href = para.url;
                //alert("PC浏览器");
            };
        }
    }
});
